package com.wc.codeforces.二进制.Binary_Colouring;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/6/8 10:23
 * @description https://codeforces.com/problemset/problem/1977/B
 */
public class Main {
    /**
     * 思路: 2 * 2 ^ i = 2 ^ (i + 1)
     * 2 ^ i + 2 ^ (i - 1) = 2 ^ (i + 1) - 2 ^ (i - 1);
     */
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 32;
    static int[] res = new int[N];
    static int n;

    public static void main(String[] args) {
        n = sc.nextInt();
        while (n-- > 0) {
            Arrays.fill(res, 0);
            int x = sc.nextInt();
            for (int i = 0; i < 30; i++) {
                if ((x >> i & 1) == 1) {
                    // 原本有一个加上当前这一个就是两个
                    if (res[i] == 1) {
                        res[i + 1] = 1;
                        res[i] = 0;
                        // 当前这个没有按照思路二，看看前面是不是1
                    } else if (i > 0) {
                        if (res[i - 1] == 1) {
                            res[i - 1] = -1;
                            res[i + 1] = 1;
                        } else {
                            res[i] = 1;
                        }
                        // 否则就当前必须是1
                    } else res[i] = 1;
                }
            }
            out.println(31);
            for (int i = 0; i <= 30; i++) out.print(res[i] + " ");
            out.println();
        }
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
